package com.lanyuan.a.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanyuan.a.atest.BaseFormMap;
import com.lanyuan.a.bean.Order;
import com.lanyuan.a.dao.BaseDao;
import com.lanyuan.a.service.OrderService;
import com.lanyuan.plugin.PageView;
@Service("orderService")
public class OrderServiceImpl implements OrderService {
	@Autowired
	public BaseDao<Order> baseDao;

	@Override
	public void addOrder(Order order) {
		baseDao.save(order);
	}

	@Override
	public List<Order> listByPage(int userid ,  String isbuy , BaseFormMap formMap) {
		PageView pageView = (PageView)formMap.get("paging");
		int first = pageView.getPageNow();
		int max = pageView.getPageSize();
		String countHql = "select count (1) from Order o where o.isbuy = ? and o.userId = ?";
		Long count = baseDao.count(countHql, new Object[]{isbuy,userid});
		pageView.setRowCount(count);
		return baseDao.find("from Order o where o.isbuy = ? and o.userId = ? order by o.ordertime desc", new Object[]{isbuy,userid}, first , max);
	}

	@Override
	public Order getById(String id) {
		return baseDao.get("from Order o where o.id = ?", new Object[]{Integer.parseInt(id)});
	}
	
	
}
